package 笔试真题;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Tengxun2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] res = new int[n];
        for (int j = 0; j < n; j++) {
            int k = scanner.nextInt();
            Integer[] ints = new Integer[k];
            for (int i = 0; i < k; i++) {
                ints[i] =  scanner.nextInt();
            }
            Arrays.sort(ints,Comparator.reverseOrder());
            int ans =0 ;
            for (int i = 0; i < k; i++) {
                ans += ints[i];
                for (int l = i+1; l < k; l++) {
                    ints[l] += ints[i] % 1000000007;
                }
            }
            System.out.println(ans);
        }




    }
}
